package cloud.xiguapi.ubas.controller;

import cloud.xiguapi.ubas.common.ApiResult;
import cloud.xiguapi.ubas.common.Pager;
import cloud.xiguapi.ubas.entity.BlacklistAdvertising;
import cloud.xiguapi.ubas.service.IAdvertisingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static cloud.xiguapi.ubas.constant.FilenameConstant.AD_CLICK_LOG;
import static cloud.xiguapi.ubas.constant.GlobalConstant.DEV;

/**
 * @author 大大大西西瓜皮🍉
 * date: 2021-5-20 下午 08:56
 * desc:
 */
@RestController
@RequestMapping("/blacklist-advertising")
public class BlacklistAdvertisingController {

    private final IAdvertisingService<BlacklistAdvertising> advertisingService;

    @Autowired
    public BlacklistAdvertisingController(IAdvertisingService<BlacklistAdvertising> advertisingService) {
        this.advertisingService = advertisingService;
    }

    @GetMapping("/analysis")
    public ApiResult<Object> analysis() {
        return advertisingService.analysis(DEV.getPrefix() + AD_CLICK_LOG.getFilename());
    }

    @GetMapping("/select/{current}/{size}")
    public ApiResult<Pager<BlacklistAdvertising>> selectPage(@PathVariable long current, @PathVariable long size) {
        if (current <= 0) {
            current = 1;
        }
        if (size <= 0) {
            size = 10;
        }
        return advertisingService.selectPage(current, size);
    }
}
